<template>
  <div class="list-table">
    <div class="area-header">
      <span class="area-header-title">{{ $t('事项申请') }}</span>
    </div>
    <el-form ref="queryForm" :model="queryParams" :inline="true">
      <el-form-item :label="$t('申请事项')" prop="actTitle">
        <el-input
          v-model="queryParams.actTitle"
          size="small"
          :placeholder="$t('申请事项')"
          clearable
          @keyup.enter.native="queryHandle"
        />
      </el-form-item>
      <el-form-item :label="$t('备注')" prop="remark">
        <el-input
          v-model="queryParams.remark"
          size="small"
          :placeholder="$t('备注')"
          clearable
          @keyup.enter.native="queryHandle"
        />
      </el-form-item>
      <el-form-item :label="$t('审批状态')" prop="actStatus">
        <el-select v-model="queryParams.actStatus" size="small" :placeholder="$t('审批状态')" clearable>
          <el-option
            v-for="dict in workFlowStatusOptions"
            :key="dict.dictValue"
            :label="$t(dict.dictLabel)"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="queryHandle">{{ $t("搜索") }}</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">{{ $t("重置") }}</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="addHandle"
        >{{ $t("新增") }}</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          v-hasPermi="['oa:matters:export']"
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="exportHandle"
        >{{ $t("导出") }}</el-button>
      </el-col>
    </el-row>

    <el-table v-loading="loading" tooltip-effect="darkTable" :data="oaMattersList" border>
      <el-table-column :label="$t('序号')" type="index" align="center" width="50">
        <template slot-scope="scope">
          {{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}
        </template>
      </el-table-column>
      <el-table-column :label="$t('申请事项')" align="left" prop="actTitle" show-overflow-tooltip>
        <template slot-scope="scope">
          <el-link type="primary" @click="updateHandle(scope.row)">{{ scope.row.actTitle }}</el-link>
        </template>
      </el-table-column>
      <el-table-column :label="$t('申请人')" align="center" prop="applicantName" show-overflow-tooltip width="120" />
      <el-table-column :label="$t('申请时间')" align="center" prop="applicationTime" show-overflow-tooltip width="120">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.applicationTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('备注')" prop="remark" align="center" show-overflow-tooltip />
      <el-table-column fixed="right" :label="$t('审批状态')" show-overflow-tooltip align="center" width="120">
        <template slot-scope="scope">
          <ProcessStatus :status="scope.row.actStatus" :act-id="scope.row.actId" />
        </template>
      </el-table-column>
      <el-table-column :label="$t('操作')" fixed="right" align="center" class-name="small-padding fixed-width" width="200">
        <template slot-scope="scope">
          <ListBtn :bus-data="scope.row" has-permi="oa:matters" />
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改事项申请对话框 -->
    <el-dialog :title="$t(title)" :visible.sync="formOpen" width="50%" :close-on-click-modal="false" :lock-scroll="false" custom-class="dialogForm">
      <oaMattersForm ref="oaMattersForm" />
    </el-dialog>
  </div>
</template>

<style scoped>
.tooltip {
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
}
</style>

<script>
import {
  listOaMatters,
  delOaMatters
} from '@/api/oa/matters/oaMatters'
import oaMattersForm from './oaMattersForm.vue'
import ProcessStatus from '@/components/Act/ProcessStatus'
export default {
  components: {
    oaMattersForm,
    ProcessStatus
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      // 事项申请表格数据
      oaMattersList: [],
      // 流程审批状态
      workFlowStatusOptions: [],
      // 弹出层标题
      title: '事项申请',
      // 是否显示弹出层
      formOpen: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        actTitle: undefined,
        remark: undefined,
        actStatus: undefined
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {}
    }
  },
  created() {
    this.getList()
    this.getDicts('work_flow_status').then(response => {
      this.workFlowStatusOptions = response.data
    })
  },
  methods: {
    /** 查询事项申请列表 */
    getList() {
      this.loading = true
      listOaMatters(this.queryParams).then(response => {
        this.oaMattersList = response.rows
        this.total = response.total
        this.loading = false
      })
    },

    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        matters: undefined,
        remark: undefined,
        createBy: undefined,
        createTime: undefined,
        updateBy: undefined,
        updateTime: undefined,
        actStatus: undefined,
        delFlag: undefined
      }
      this.resetForm('form')
    },
    /** 搜索按钮操作 */
    queryHandle() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.queryHandle()
    },
    /** 新增按钮操作 */
    addHandle() {
      this.formOpen = true
      this.$nextTick(() => {
        this.$refs.oaMattersForm.init(null)
      })
    },
    /** 修改按钮操作 */
    updateHandle(row) {
      this.formOpen = true
      this.$nextTick(() => {
        this.$refs.oaMattersForm.init(row)
      })
    },
    /** 删除按钮操作 */
    deleteHandle(row) {
      this.$confirm(this.$t('是否确认删除?'), this.$t('警告'), {
        confirmButtonText: this.$t('确定'),
        cancelButtonText: this.$t('取消'),
        type: 'warning'
      })
        .then(function() {
          return delOaMatters(row.id)
        })
        .then(() => {
          this.getList()
          this.msgSuccess(this.$t('删除成功'))
        })
        .catch(function() {})
    },
    /** 导出按钮操作 */
    exportHandle() {
      this.downLoadExcel('/matters/oaMatters/export', this.queryParams)
    }
  }
}
</script>
